package com.cloud.controller;


import com.cloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("payment")
@Slf4j
public class PaymentController {
    /**
     * 服务对象
     */
    @Resource
    private PaymentService paymentService;

//    @Value("${server.port}")
//    private String serverPort;

    /**
     * 正常访问或者异常
     * @param id
     * @return
     */
    @GetMapping("/hystrix/ok/{id}")
    public String paymentInfoOK(@PathVariable("id") Integer id) {
        String result = paymentService.paymentOKOrFallback(id);
        log.info("result: " + result);
        return result;
    }

    /**
     * 超时
     * @param timeout
     * @return
     */
    @GetMapping("/hystrix/timeout/{timeout}")
    public String paymentTimeOut(@PathVariable("timeout") Long timeout) {
        String result = paymentService.paymentTimeOut(timeout);
        log.info("result: " + result);
        return result;
    }


//    /**
//     * 服务熔断
//     *
//     * @param id
//     * @return
//     */
//    @GetMapping("/circuit/{id}")
//    public String paymentCircuitBreaker(@PathVariable("id") Integer id) {
//        String result = paymentService.paymentCircuitBreaker(id);
//        log.info("****result: " + result);
//        return result;
//    }
}